package audi.a4.control.core;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

public enum AudiA4CanCode {
	UNKNOWN(0x000),
	ECU_1(0x0C2),
	ECU_2(0x280),
	ECU_3(0x288),
	ECU_4(0x380),
	ECU_5(0x488),
	AIRBAG_1(0x5E0),
	AIRBAG_2(0x050),
	AIRBAG_3(0x1A0),
	AIRBAG_4(0x4A0),
	AIRBAG_5(0x4A8),
	AIRBAG_6(0x5A0),
	CLUSTER_1(0x320),
	CLUSTER_2(0x38A),
	CLUSTER_3(0x420),
	CLUSTER_4(0x480),
	CLUSTER_5(0x520),
	CLUSTER_6(0x580),
	CLUSTER_7(0x588),
	CLUSTER_8(0x5D0),
	CLUSTER_9(0x5D2),
	CLUSTER_10(0x5D8),
	TRANSMISSION_1(0x440),
	TRANSMISSION_2(0x540);
	
	private static final Map<Integer,AudiA4CanCode> lookup = new HashMap<Integer,AudiA4CanCode>();
	
	static {
		for(AudiA4CanCode cm : EnumSet.allOf(AudiA4CanCode.class)) {
			lookup.put(cm.getValue(), cm);
		}
	}
	
	/** The value. */
	private int value;
	
	private int code;
	
	/**
	 * Instantiates a new bowler method.
	 *
	 * @param val the val
	 */
	private AudiA4CanCode(int val) {
		value = val;
		code = val;
	}
	
	/**
	 * Gets the value.
	 *
	 * @return the value
	 */
	private int getValue() {
		return value; 
	}
	
	/**
	 * Gets the actual code.
	 *
	 * @return the value
	 */
	public int getCode() {
		return code; 
	}
	/**
	 * Gets the actual code.
	 *
	 * @return the value
	 */
	public static String getCodeHex(int code) {
		String s = Integer.toHexString(code);
		if (s.length() == 1)
			s="00"+s;
		if (s.length() == 2)
			s="0"+s;
		return s; 
	}
	
	/**
     * Gets the.
     *
     * @param code the code
     * @return the bowler method
     */
    public static AudiA4CanCode get(String code) { 
    	return get(Integer.parseInt(code, 16));
    }

    /**
     * Gets the.
     *
     * @param code the code
     * @return the bowler method
     */
    public static AudiA4CanCode get(int code) { 
    	AudiA4CanCode c = lookup.get(code);
    	if(c==null) {
    		c= AudiA4CanCode.UNKNOWN;
    	}
    	return c; 
    }

	public void setCode(int code) {
		this.code = code;
	}
}
